#pragma once

#include "stdafx.h"

#include "core/event.h"
#include "core/task.h"
#include "util/backgroundprocessor.h"

namespace natrium {
	namespace core {
		class Kernel {
		public:
			typedef std::shared_ptr<Task> TaskPtr;

			struct StopEvent {};

			Kernel();
			~Kernel();

			void add(const TaskPtr& task);
		
			void start();
			void stop();

			void execute(const TaskPtr& task);

			void operator()(const StopEvent&);
			void operator()(const Task::TaskCompleted& tc);

		private:
			Kernel(const Kernel&);
			Kernel& operator= (const Kernel&);

			typedef std::vector<TaskPtr> TaskList;
		
			TaskList mTaskList;
			
			std::mutex mMutex;

			bool mRunning;

			EventChannel mChan;
			util::BackgroundProcessor mProcessor;
		};
	}
}